const path = require("path");
const fs = require("fs");

class Log {

    static writeStream = function () {
        if (fs.existsSync(path.join(__dirname, "../../../..", "log"))) {
            return fs.createWriteStream(path.join(__dirname, "../../../..", "log", "log.txt"), { flags: "a" });
        }
        else {
            return fs.createWriteStream(path.join(__dirname, "log.txt"), { flags: "a" });
        }
    }();

    static write(log) {
        let now = new Date();
        Log.writeStream.write(`--------------------${now.toLocaleString()}.${now.getMilliseconds().toString().padStart(3, "0")}--------------------\n`);
        Log.writeStream.write(log + "\n");
    }

}

module.exports = Log;